package com.blrs.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.blrs.system.domain.SysUserDataView;
import com.blrs.system.service.ISysUserDataViewService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.blrs.common.annotation.Log;
import com.blrs.common.core.controller.BaseController;
import com.blrs.common.core.domain.AjaxResult;
import com.blrs.common.enums.BusinessType;
import com.blrs.common.utils.poi.ExcelUtil;
import com.blrs.common.core.page.TableDataInfo;

/**
 * 指定数据权限Controller
 * 
 * @author yuxiang.chen
 * @date 2023-07-14
 */
@RestController
@RequestMapping("/system/view")
public class SysUserDataViewController extends BaseController
{
    @Autowired
    private ISysUserDataViewService sysUserDataViewService;

    /**
     * 查询指定数据权限
     */
    //@PreAuthorize("@ss.hasPermi('system:view:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysUserDataView sysUserDataView)
    {
        startPage();
        List<SysUserDataView> list = sysUserDataViewService.selectSysUserDataViewList(sysUserDataView);
        return getDataTable(list);
    }

    /**
     * 导出指定数据权限
     */
    //@PreAuthorize("@ss.hasPermi('system:view:export')")
    @Log(title = "导出", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysUserDataView sysUserDataView)
    {
        List<SysUserDataView> list = sysUserDataViewService.selectSysUserDataViewList(sysUserDataView);
        ExcelUtil<SysUserDataView> util = new ExcelUtil<SysUserDataView>(SysUserDataView.class);
        util.exportExcel(response, list, "【请填写功能名称】数据");
    }

    /**
     * 获取指定数据权限
     */
    //@PreAuthorize("@ss.hasPermi('system:view:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(sysUserDataViewService.selectSysUserDataViewById(id));
    }

    /**
     * 新增指定数据权限
     */
    //@PreAuthorize("@ss.hasPermi('system:view:add')")
    @Log(title = " 新增", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysUserDataView sysUserDataView)
    {
        return toAjax(sysUserDataViewService.insertSysUserDataView(sysUserDataView));
    }

    /**
     * 修改指定数据权限
     */
    //@PreAuthorize("@ss.hasPermi('system:view:edit')")
    @Log(title = "修改", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysUserDataView sysUserDataView)
    {
        return toAjax(sysUserDataViewService.updateSysUserDataView(sysUserDataView));
    }

    /**
     * 删除指定数据权限
     */
    //@PreAuthorize("@ss.hasPermi('system:view:remove')")
    @Log(title = "删除", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysUserDataViewService.deleteSysUserDataViewByIds(ids));
    }
}
